﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class login : System.Web.UI.Page
{
    int admin_id;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btLogin_Click(object sender, EventArgs e)
    {
        LoginBT lg = new LoginBT();
        string na = this.name.Text;
        string pw = this.pwd.Text;
        //获取浏览器高度
        //string h = this.browserHeight.Text;
        //int hg = int.Parse(h);
        //int ch = hg - 127 - 11;
        //string centerHeight = ch.ToString() + "px";
        if (this.name.Text.Trim().Length == 0)
        {
            this.lb1.Text = "账号不能为空";
            return;
        }
        if (this.pwd.Text.Trim().Length == 0)
        {
            this.lb1.Text = "密码不能为空";
            return;
        }
        string type = this.ddlType.SelectedValue;
        if (type == "学生")
        {
            int sid = lg.checkloginMegOfNormal(na, pw);
            if (sid > 0)
            {
                Session.Add("student_id", sid);
                Session.Add("type", "normal");
                Response.Redirect("home.aspx");
            }
            else
            {
                this.lb1.Text = "账号或密码错误。请选择正确的登陆身份。";
            }
        }
        else if (type == "管理员")
        {
            admin_id = lg.checkloginMeg(na, pw);
            if (admin_id > 0)
            {
                Session.Add("admin_id", admin_id);
                Session.Add("type", "admin");
                Response.Redirect("admin.aspx");
            }
            else
            {
                this.lb1.Text = "账号或密码错误。请选择正确的登陆身份。";
            }
        }
        else
        {
            this.lb1.Text = "请选择登陆身份。";
        }
       
    }
    protected void btReset_Click(object sender, EventArgs e)
    {
        this.name.Text = "";
        this.pwd.Text = "";
        this.lb1.Text = "";
    }
}
